package com.dpf.api.utills;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ListUtils {

    public static <T> boolean isIntersection(List<T> list1, List<T> list2) {
        for (T t1 : list1) {
            for (T t2 : list2) {
                if (t1.equals(t2))
                    return true;
            }
        }
        return false;
    }


    public static List<String> repaet(List<String> soruce){
        List<String> result=new ArrayList<>();
        Map<String, Integer> map = new HashMap<>();
        for (String s : soruce) {
            //1:map.containsKey()   检测key是否重复
            if (map.containsKey(s)) {
                Integer num = map.get(s);
                map.put(s, num + 1);
            } else {
                map.put(s, 1);
            }
        }
        map.forEach((k,v)->{
            if (v>1)
                result.add(k);
        });

        return result;

    }



    public static List<String> initList(long count,String item){
        List<String> result=new ArrayList<>();
        for (int i = 0; i <count ; i++) {
            result.add(item);
        }
        return result;
    }





}
